ActionController::Routing::Routes.draw do |map|
  map.index '', :controller  => 'browse', :action => 'index'
  
  # The priority is based upon order of creation: first created -> highest priority.
  
  # Sample of regular route:
  # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
  # Keep in mind you can assign values other than :controller and :action

  # Sample of named route:
  # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
  # This route can be invoked with purchase_url(:id => product.id)

  # You can have the root of your site routed by hooking up '' 
  # -- just remember to delete public/index.html.
  # map.connect '', :controller => "welcome"

  # Allow downloading Web Service WSDL as a file with an extension
  # instead of a file named 'wsdl'
  map.connect ':controller/service.wsdl', :action => 'wsdl'

  # Install the default route as the lowest priority.
  #map.index '', :controller  => 'browse', :action => 'index'
  
  map.resources :users, :member => { :friends => :get, :rfriends => :get, :connect => :post, :disconnect => :post, :replies => :get, :posts => :get }, :collection => { :check_invite => :any, :invite => :any, :search => :get, :change_password => :any, :update_icon => :post, :login => :any, :logout => :any, :signup => :any, :forgot_password => :any } do |user|
    user.resources :talks, :collection => { :friends => :get, :all => :get }, :name_prefix => nil
  end
  
  map.resources :districts, :member => { :forums => :get, :sites => :get, :users => :get, :search_users => :get } do |district|
    district.resources :communities, :member => { :forums => :get, :sites => :get, :cats => :get, :add_site => :any, :users => :get, :live => :post, :search_users => :get, :set_neighbor => :post }, :name_prefix => nil do |community|
      community.resources :common_posts, :controller => "posts", :name_prefix => nil do |post|
        post.resources :community_post_replies, :controller => "replies", :name_prefix => nil
      end
    end
  end
  
  map.resources :districts do |district|
      district.resources :dist_posts, :controller => "posts", :name_prefix => nil do |post|
        post.resources :district_post_replies, :controller => "replies", :name_prefix => nil
      end
  end
  
  map.resources :posts,  :name_prefix => 'all_', :collection => { :group => :get, :common => :get, :site => :get }
  
  map.resources :groups, :collection => { :all => :get, :search => :get, :search_posts => :get }, :member => { :search_users => :get, :manage_users => :get, :users => :get, :update_icon => :any, :newpost => :any, :posts => :get, :join => :post, :quit => :post, :kick => :post } do |group|
    group.resources :group_posts, :controller => "posts", :name_prefix => nil do |post|
      post.resources :group_post_replies, :controller => "replies", :name_prefix => nil
    end
  end
  
  map.resources :sites, :member => { :newpost => :any, :update_icon => :any, :set_neighbor => :post, :votegood => :post, :votebad => :post }, :collection => {:search => :get } do |site|
    site.resources :site_posts, :controller => "posts", :name_prefix => nil do |post|
      post.resources :site_post_replies, :controller => "replies", :name_prefix => nil
    end
  end
  
  map.resources :topics, :path_prefix => '/forums', :name_prefix => 'all_', :collection => { :search => :get }
  
  map.resources :forums, :collection => { :search => :get } do |forum|
    forum.resources :topics, :member => {:reply => :post}, :name_prefix => nil do |topic|
        topic.resources :topic_replies, :controller => "topics", :member => {:delete_reply => :delete}, :name_prefix => nil
    end
  end
  
  map.resources :messages, :member => { :deliver => :any }, :collection => { :batch_delete => :delete, :sendbox => :get }
  
  map.resources :categories
  
  map.resources :tags, :member => { :user => :get }
  
  #admin routes
  map.namespace(:admin) do |admin|
    admin.resources :users, :member => {:update_icon => :any, :change_password => :any }, :collection => { :login => :any, :logout => :any, :batch_deal => :post }
    admin.resources :posts
    
    admin.resources :districts, :member => { :import => :post, :create_forum => :post } do |district|
      district.resources :communities do |community|
        community.resources :common_posts, :controller => "posts", :name_prefix => 'admin_' do |post|
          post.resources :community_post_replies, :controller => "replies"
        end
      end
    end
    
    admin.resources :sites, :member => { :show_category => :get, :new_category => :any, :edit_category => :any, :destroy_category => :delete }, :collection => {:list_category => :get, :search => :get } do |site|
      site.resources :site_posts, :controller => "posts", :name_prefix => 'admin_' do |post|
        post.resources :site_post_replies, :controller => "replies"
      end
    end
    
    admin.resources :groups, :collection => { :search => :get }, :member => { :kick_user => :put } do |group|
      group.resources :group_posts, :controller => "posts", :name_prefix => 'admin_' do |post|
        post.resources :group_post_replies, :controller => "replies"
      end
    end
    
    admin.resources :site_categories
    admin.resources :messages, :member => { :deliver => :any }
    admin.resources :categories, :member => { :new_child => :any }
  end
  #end admin routes
  
  map.resources :comments
  
  map.connect ':controller/:action/:id'
  
end
